#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e6 + 5;
#define ll long long
#define ls rt << 1
#define rs rt << 1 | 1

struct Tree {
    ll sum[maxn << 2], tag[maxn << 2];
    int L[maxn << 2], R[maxn << 2];

    void build(int rt, int l, int r) {
        L[rt] = l, R[rt] = r;

        if (l == r) {
            cin >> sum[rt];
            return;
        }

        int mid = (l + r) >> 1;
        build(ls, l, mid);
        build(rs, mid + 1, r);
        sum[rt] = sum[ls] + sum[rs];
    }

    ll query(int rt, int l, int r, ll res = 0) {
        if (L[rt] == l && R[rt] == r)
            return sum[rt] + res * (r - l + 1);

        res += tag[rt];
        int mid = (L[rt] + R[rt]) >> 1;

        if (r <= mid)
            return query(ls, l, r, res);

        if (l >= mid + 1)
            return query(rs, l, r, res);

        return query(ls, l, mid, res) + query(rs, mid + 1, r, res);
    }

    void add(int rt, int l, int r, int val) {
        sum[rt] += 1LL * val * (r - l + 1);

        if (l == L[rt] && r == R[rt]) {
            tag[rt] += val;
            return;
        }

        int mid = (L[rt] + R[rt]) >> 1;

        if (r <= mid)
            add(ls, l, r, val);
        else if (l >= mid + 1)
            add(rs, l, r, val);
        else
            add(ls, l, mid, val), add(rs, mid + 1, r, val);
    }
} T;

void Main() {
    int n, m;
    cin >> n >> m;
    T.build(1, 1, n);

    while (m--) {
        int op, l, r;
        cin >> op >> l >> r;

        if (op == 1) {
            int val;
            cin >> val;
            T.add(1, l, r, val);
        }

        if (op == 2)
            cout << T.query(1, l, r) << '\n';
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    Main();
    return 0;
}
